from PyQt4 import QtCore
import sys,os,inspect
sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(), os.pardir)))## add root path 
from KDataBase.KDBManager import KDBManager
from KDataBase import KBuildDB,KQueryDB,KDBUtility
from KDataBase.KUpdateDB import KUpdateDB
from KModel.KSingleStock import KSingleStock
from subprocess import check_output
class KAutomaticPyuic(QtCore.QObject):

	def __init__(self):
		super(KAutomaticPyuic, self).__init__()
	def ScanUis(self,path):
		subfolders = os.listdir(path)
		for sub_dir in subfolders:
			abspath=os.path.join(path, sub_dir)
			if os.path.isdir(abspath):
				self.ScanUis(abspath) 
			else:
				if abspath.endswith('.ui'):
					(folder,filename)=abspath.rsplit('\\',1)
					filename='ui_'+filename.replace('.ui','.py')
					newpath=folder+'\\'+filename
					cmdstr=r' python C:\WinPython-64bit-2.7.5.1\python-2.7.5.amd64\Lib\site-packages\PyQt4\uic\pyuic.py '+ abspath + ' -o '+newpath
					print('translating %s'%(filename))
					print(check_output(cmdstr, shell=True))
					

if __name__ == "__main__":
	#app = QtCore.QCoreApplication(sys.argv)
	console = KAutomaticPyuic()
	console.ScanUis(u'D:\Dropbox\Trading2013\KunTrading')

	#console.RunTest()
	#sys.exit(app.exec_())